﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

using ProjectBase.Core;
using ProjectBase.Data;
using ProjectBase.Data.NH;

using Survey.Common.Data;
using Survey.Common.Data.Services;
using Survey.Entity.Services;

namespace Survey.Data.Services
{
    public class ArticleDao : BaseDao<Article, int, ArticleFilter>, IArticleDao
    {
        #region IArticleDao Members
        /// <summary>
        ///     Evaluates all filters and order-by clauses
        ///     and returns sorted list of matching Article entities
        /// </summary>
        /// <param name = "filter">ISearchObject&lt;Article&gt; containing ArticleFilter not-null instance</param>
        /// <returns>List of Article entities matching the searching criteria</returns>
        public override IEnumerable<Article> Find(ArticleFilter filter)
        {
            Criteria.AddCompare(() => filter.IdExact); // Searches for exact ID
            Criteria.AddEqual(() => Entity.Code, filter.CodeExact); // Searches for exact Code even string.Empty

            Criteria.AddLike(() => filter.Code);
            Criteria.AddLike(() => filter.Title);
            Criteria.AddLike(() => filter.Description);
            Criteria.AddLike(() => filter.Text);

            Criteria.AddEqual(() => filter.ArticleCategory);
            Criteria.AddEqual(() => filter.ArticleGroup);

            Criteria.AddNotEqual(() => Entity.ArticleCategory, filter.ArticleCategoryNot);
            Criteria.AddNotEqual(() => Entity.ArticleGroup, filter.ArticleGroupNot);


            Criteria.AddEqual(() => Entity.IsVisible, filter.IsVisible);

            Criteria.AddCompare(() => Entity.CreationDate, Sign.GreaterOrEqual, filter.CreatedFrom);
            Criteria.AddCompare(() => Entity.CreationDate, Sign.LessOrEqual, filter.CreatedTo);

            Criteria.AddCompare(() => Entity.LastUpdateDate, Sign.GreaterOrEqual, filter.UpdatedFrom);
            Criteria.AddCompare(() => Entity.LastUpdateDate, Sign.LessOrEqual, filter.UpdatedTo);

            Criteria.AddCompare(() => Entity.ReleaseDate, Sign.GreaterOrEqual, filter.ReleaseFrom);
            Criteria.AddCompare(() => Entity.ReleaseDate, Sign.LessOrEqual, filter.ReleaseTo);

            return GetListByCriteria(filter);
        }

        public IArticleCategoryDao ArticleCategoryDao { protected get; set; }
        public IArticleGroupDao ArticleGroupDao { protected get; set; }
        #endregion
    }
}